define(
		[ "PDUtilDir/grid", "PDUtilDir/util", "PDUtilDir/tool", "PDUtilDir/slidebar",
				"PDUtilDir/inputSelect", "PDUtilDir/fileupload/multiFileUpload" ],
		function(Grid, Util, Tool, Slidebar, inputSelect, MFU) {
			function addTicketSupportInit($scope, $compile) {
				return new addTicketSupport($scope, $compile);
			}
			;
			function addTicketSupport($scope, $compile) {
				this.$scope = $scope;
				this.$compile = $compile;
			}
			;
			addTicketSupport.fn = addTicketSupport.prototype;
			addTicketSupport.fn.init = function(id) {
				var _this = this;
				if(_this.entity && _this.entity.type){
					_this.entity = {
						type: _this.entity.type
					};
				}else{
					_this.entity = {};
				}
				//加载code
				$.ajax({
					url : getServer() + "/flea/hclv/getUUID.htmls",
					method : 'get',
					success : function(data) {
                        if (data.status != 200) {
                            return;
                        }
						_this.entity.code = data.data;
						_this.digest();
					}
				});
                _this.cache = _this.cache ? _this.cache : {
                    spotId : id,
                    typeMap: new Map()
				}
                // _this.cache = {
                //     spotId : _this.cache ? _this.cache.spotId : id,
                //     typeMap: _this.cache ? _this.cache.typeMap : new Map()
                // }
			};
			addTicketSupport.fn.digest = function() {
				this.$scope.$digest();
			};
			addTicketSupport.fn.run = function(id) {
				var _this = this;
				_this.init(id);
				this.slidebars = Slidebar({
					size : 'lg',
					url : getServer()
							+ "/static/app/spots/mySpotInfos/views/addSpotsTicket.html",
					$scope : this.$scope,
					$compile : this.$compile,
					afterLoad : function($Panel) {
						_this.initialization();
					}
				});
			};
			addTicketSupport.fn.initialization = function() {
				this.baseInit();
			};
			addTicketSupport.fn.baseInit = function() {
				var _this = this;
				
				$.ajax({
	                url:getServer()+"/flea/dict/initTree.htmls",
	                async:false,
	                data:{'dictCode':'D_SPOT_TICKET_TYPE'},
	                success:function(data){
	                    var types = data;

                        $.each(types, function(index, row) {
                            _this.cache.typeMap.set(row.dictCode, row.dictName);
                        });

	                    inputSelect.dropCache();
	                    inputSelect({
	                        id:"ticketTypeName",
	                        key : {
	                            id : "dictCode",
	                            name : "dictName",
	                            data : "data"
	                        },
	                        data : types,
	                        callback : function(id, data) {
	                        	_this.entity.type = id[0];
	                        	_this.$scope.addTicketForm.type.$setViewValue(_this.entity.type);
	                        }
	                    });
						_this.rendGrid();
	                }
	            });
			};
            addTicketSupport.fn.rendGrid = function() {
                var _this = this;
                _this.grid = Grid({
                    id : "ticketGird",
                    pageSize : 10,
                    pagination : true,
                    cache : false,
                    layout : [/* {
                                name : "门票代码",
                                field : "code",
                                sort : true
                            }, */{
                        name : "类型",
                        field : "type",
                        format : function(e) {
                            return _this.cache.typeMap.get(e.row.type);
                        }
                    }, {
                        name : "成本价格",
                        field : "price"
                    }, {
                        name : "外卖价格",
                        field : "salePrice"
                    }, {
                        name : "数量",
                        field : "number",
                        width : "10%"
                    } ],
                    data : {
                        type : "URL",
                        value : getServer() + "/flea/hclv/spotTicket/selectBySpotId.htmls"
                    },
                    queryParam : {
                        'spotId' : _this.cache.spotId
                    }
                });
            };
			addTicketSupport.fn.save = function() {
				var _this = this;
				$.ajax({
					url : getServer() + "/flea/hclv/spotTicket/saveOrUpdateSpotTicket.htmls",
					data : {"model":JSON.stringify(_this.entity), 'spotId': _this.cache.spotId},
					success : function(data) {
                        if (data.status != 200) {
                            return;
                        }
						_this.init();
						_this.grid.refresh();
						Util.alert(data.message);
					}
				});
			};
			return addTicketSupportInit;
		});